#pragma once

#include "Applications/QtBaseApplication.h"
#include "Graphics/gui/ButtonItem.h"
#include "EnemyMissile.h"
#include "FriendlyMissile.h"
#include "Graphics/gui/ButtonItem.h"
#include "Audio/Audio.h"
#include "phonon/MediaObject"

namespace QtTutorial4
{
	enum SubState
	{
		SubState_Menu,
		SubState_PlayState,
		SubState_GameOver
	};

	class QtTutorial4App : public Blobz::QtBaseApplication
	{
		Q_OBJECT
	public:
		QtTutorial4App();
		virtual ~QtTutorial4App();

	public:
		virtual bool onInitialize();
		virtual void onDeinitialize();

		virtual void onReload();

		virtual void onUpdate(float inFrameTime);
		virtual bool onEvent(QEvent *inEvent);

		virtual void onFingerDown(const TouchListener::TouchData& inData);
		virtual void onFingerUp(const TouchListener::TouchData& inData);
		virtual void onFingerUpdate(const TouchListener::TouchData& inData);
		virtual void onFingerExit(const TouchListener::TouchData& inData);
		virtual void paint(QPainter* inpPainter, const QStyleOptionGraphicsItem *inpOption, QWidget *inpWidget);

	private:
		void createStarField();
		void resetGame();
		void missileDestroyed();
		void createEnemyMissile();
		void createFriendlyMissile(const TouchListener::TouchData &inData);

	public slots:
		void startButtonClicked();
		void okButtonClicked();
		void onItemsSizeSetup();

	private:
		SubState mCurrentState;

		float mCurrentScale;

		// Counters
		int mScore;
		int mLivesRemaining;
		unsigned int mMissilesDestroyed;
		unsigned int mWaveNumber;

		// Entities
		std::vector<FriendlyMissile*> mMissiles;
		std::vector<EnemyMissile*> mEnemyMissiles;
		std::vector<EnemyMissile*> mMissilesToBeAdded;
		EnemyMissile* mItem;

		// Graphics
		QFont mStandardFont;
		Blobz::ButtonItem* mpStartButton;
		Blobz::ButtonItem* mpOkButton;
		std::vector<QPointF> mStars;
		

		// Audio
		Blobz::Audio mMusic;
		Blobz::Audio mBlip;
	};
}